var app = getApp(); //引入全局app.js，我们可以在globalData中定义一些公用的数据，比如baseUrl、token

const request = require("./request") //引入封装好的js文件
/**
 * 获取用户具体信息
 */
export function getUserByApi(data) {
  return request.post('/api/wx/userInfo', data)
}
/**
 * 获取打印机列表
 */
export function printerList(data) {
  return request.post('/api/wx/print/printer/printerList', data)
}

/**
 * 获取打印机在线信息
 * @param {*} data 
 */
export function deviceInfo(data) {
  return request.post('/api/wx/print/printer/deviceInfo', data)
}
/**
 * 获取打印文件信息
 * @param {*} data 
 */
export function getPrintFileInfo(data) {
  return request.get('/api/wx/print/file/getPrintFileInfo', data)
}
/**
 * 设置打印队列
 * @param {*} data 
 */
export function saveOrUpdatePrint(data) {
  return request.post('/api/wx/print/queue/saveOrUpdatePrint', data)
}

/**
 * 获取打印列表
 * @param {*} data 
 */
export function getQueueList(data) {
  return request.get('/api/wx/print/queue/getQueueList', data)
}
export function getJobListByOrderId(data) {
  return request.get('/api/wx/print/queue/getRunJobListByOrderId', data)
}
/**
 * 获取打印列表
 * @param {*} data 
 */
export function deleteQueueById(data) {
  return request.post('/api/wx/print/queue/deleteQueueById', data)
}
/**
 * 获取费用总额
 * @param {*} data 
 */
export function getTotalFeeByService(data) {
  return request.post('/api/wx/print/queue/getPrintFee', data)
}

/**
 * 创建支付订单
 * @param {*} data 
 */
export function createPrintOrder(data) {
  return request.post('/api/wx/print/pay/createPrintOrder', data)
}

/**
 * 发送打印
 * @param {*} data 
 */
export function sendFileToLianke(data) {
  return request.post('/api/wx/print/queue/sendFileToLianKeByOrderId', data)
}

/**
 * 获取支付状态
 * @param {*} data 
 */
export function queryPayResult(data) {
  return request.get('/api/wx/print/pay/getQueryPayResult', data)
}
export function retryPay(data) {
  return request.post('/api/wx/print/pay/retryPay', data)
}
export function cancelPay(data) {
  return request.post('/api/wx/print/pay/cancelPay', data)
}
/**
 * 上传处理身份证照片
 * @param {*} data 
 */
export function handleIdCardProcessImg(data) {
  return request.post('/api/wx/print/file/handleIdCardProcessImg', data)
}
/**
 * 查询打印状态
 * @param {*} data 
 */
export function getPrintJobStatus(data) {
  return request.get('/api/wx/print/queue/getPrintRunJobStatus', data)
}

export function getOrderList(data) {
  return request.get('/api/wx/print/order/list', data)
}

export function refundRequest(data) {
  return request.post('/api/wx/print/refund/refundRequest', data)
}
export function getPhone(data) {
  return request.post('/api/wx/phone', data)
}
export function updatePhone(data) {
  return request.post('/api/wx/updatePhone', data)
}
export function logout(data) {
  return request.post('/api/wx/logout', data)
}

export function selectPrinterInfo(printerId) {
  return new Promise((resolve, reject) => {
    let data = {
      printerId: printerId
    }
    request.get('/api/wx/print/printer/selectPrinter', data).then(res => {
        let printer = res.data.printer;
        wx.removeStorageSync('printer');
        wx.setStorageSync('printer', printer);
        app.globalData.printer = printer
        resolve(printer)
      })
      .catch(err => {
        reject('获取打印机具体信息失败', err)
      })
  })
}
export function selectDefaultPrinterInfo() {
  return new Promise((resolve, reject) => {
    request.get('/api/wx/print/printer/getDefaultPrinter').then(res => {
        if (res.code === 200) {
          let printer = res.data.printer;
          wx.removeStorageSync('printer');
          wx.setStorageSync('printer', printer);
          app.globalData.printer = printer
          resolve(printer)
        }
      })
      .catch(err => {
        reject('获取打印机具体信息失败', err)
      })
  })
}

export function getDeliveryRange(data) {
  return request.get('/api/wx/print/delivery/getDeliveryRange', data)
}
export function getPickUpList(data) {
  return request.get('/api/wx/print/delivery/getPickUpList', data)
}
export function deliverySign(data) {
  return request.post('/api/wx/print/delivery/deliverySign', data)
}
export function checkUserRole(data) {
  return request.get('/api/wx/print/order/checkUserRole', data)
}
export function getUserDeliveryAddressList(data) {
  return request.get('/api/wx/print/delivery/getUserDeliveryAddressList', data)
}
export function addUserDeliveryAddress(data) {
  return request.post('/api/wx/print/delivery/addUserDeliveryAddress', data)
}
export function editUserDeliveryAddress(data) {
  return request.post('/api/wx/print/delivery/editUserDeliveryAddress', data)
}
export function removeUserDeliveryAddress(data) {
  return request.get('/api/wx/print/delivery/removeUserDeliveryAddress', data)
}
export function getUserInfo(data) {
  return request.get('/api/wx/getUserInfo', data)
}
export function updateUser(data) {
  return request.post('/api/wx/updateUser', data)
}